package com.societyGames.catExercises
{
	import com.greensock.TweenNano;
	import com.societyGames.action.Action;

	public class BuySurplusClothingAction extends Action
	{
		private var _surplusDisplay:SurplusDisplay;
		private var _totalCount:int;
		private var _x:Number;
		private var _y:Number;
		private const _fadeDuration:Number = 0.25;
		
		public function BuySurplusClothingAction(surplusDisplay:SurplusDisplay, totalCount:int)
		{
			this._surplusDisplay = surplusDisplay;
			this._totalCount = totalCount;
		}

		public override function startAction():void
		{
			if (!this._surplusDisplay.visible)
			{
				this._surplusDisplay.visible = true;
				this._surplusDisplay.alpha = 0;
				TweenNano.to(this._surplusDisplay, _fadeDuration, {alpha:1, onComplete:onComplete});	
			}
			else
			{
				incrementCount();				
			}	
		}
		
		private function onComplete():void
		{
			incrementCount();
		}
		
		private function incrementCount():void
		{
			this._surplusDisplay.count = this._totalCount;
			this._completeEventObject.dispatchEvent();
		}
	}
}